package cn.ztuo.bitrade.controller;


import cn.ztuo.bitrade.entity.AppRevision;
import cn.ztuo.bitrade.entity.IeoEmption;
import cn.ztuo.bitrade.entity.IeoOdf;
import cn.ztuo.bitrade.service.*;
import cn.ztuo.bitrade.util.MessageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author fiwork.net
 * @Title: ${file_name}
 * @Description:
 * @date 2019/4/1816:54
 */
@RestController
@RequestMapping("exchange-coin")
public class ExchangeCoinController extends BaseController {
    @Autowired
    private ExchangeCoinService service;
    @Autowired
    private IeoEmptionService ieoEmptionService;
    @Autowired
    private AppRevisionService appRevisionService;
    @Autowired
    private LocaleMessageSourceService msService;
    @Autowired
    private IeoOdfService ieoOdfService;

    //获取基币
    @RequestMapping("base-symbol")
    public MessageResult baseSymbol() {
        List<String> baseSymbol = service.getBaseSymbol();
        if (baseSymbol != null && baseSymbol.size() > 0) return success(baseSymbol);
        return error("baseSymbol null");

    }
    //获取IEO
    @RequestMapping("ieo-emption")
    public Object emption(){
        //过滤软删除计划
        int status = 3;
        List<IeoEmption> emptions = ieoEmptionService.findByStatus(status);
        if(emptions.size() > 0) return success(emptions);
        return error("emption null");
    }


    //获取ODFIEO
    @RequestMapping("odf-emption")
    public MessageResult odfEmption(){
        List<IeoOdf> emptions = ieoOdfService.findAll();
        if(emptions.size() > 0) return success(emptions);
        return error("emption null");
    }

    /**
     * APP版本号
     * @return
     */
    @RequestMapping("/system/appVersion")
    public MessageResult version(@RequestParam(defaultValue = "1") Long id) {
        if(id==null){
            id=1L;
        }
        AppRevision revision = appRevisionService.findById(id);
        if(revision != null){
            MessageResult result = MessageResult.success();
            result.setData(revision);
            return result;
        }
        else{
            return MessageResult.error(msService.getMessage("NO_UPDATE"));
        }
    }
}
